import random
import matplotlib.pyplot as plt


def oozing(x0, p, cycle=20):
    plt.figure()
    plt.grid()
    plt.title("Simulation")
    plt.xlabel("x")
    plt.ylabel("y")
    plt.xticks(range(0, 81, 2), rotation=45)
    plt.yticks(range(0, 61, 2), rotation=45)
    x0_constant = x0

    while cycle > 0:
        cycle -= 1
        a = []
        b = []
        x0 = x0_constant
        y0 = 1
        while y0 < 60:
            a.append(x0)
            b.append(y0)
            # 丢骰子
            rn = random.uniform(0, 1)
            # 判断下一步的走向
            if 0 < rn <= p:
                x0 -= 1
                y0 += 1
            elif 1-p <= rn <=1:
                x0 += 1
                y0 += 1
            else:
                break
            # 判断是否出界
            if x0 <= 0 or x0 >= 80:
                break
        plt.plot(a, b)
    plt.show()


if __name__ == "__main__":
    oozing(x0=33, p=0.45, cycle=10)
